import React, { useState,useEffect } from 'react';
import { Modal, Button,Row,Col } from 'antd';
import axios from "axios";


/**
 * 下架菜品的 方法
 * @returns 
 */
 function closeCui(id,version){
  axios({
    headers: {
      'tenantId':500,
      "userId":11111
  },
    method: 'post',
    url:`http://localhost:9101/product/${id}/disable`,
    data: {
    "version":version
    }

  }).then((data)=>{


  })

 }

 /**
 * 上架菜品的 方法
 * @returns 
 */
  function upCui(id,version){
    axios({
      headers: {
        'tenantId':500,
        "userId":11111
    },
      method: 'post',
      url:`http://localhost:9101/product/${id}/enable`,
      data: {
      "version":version
      }
  
    }).then((data)=>{

    })
  
   }

 
 const CancelModel = (props) => {
  const [isModalVisible, setIsModalVisible] = useState(false);
    useEffect(()=>{
        setIsModalVisible(props.store.startStopModelStatus);
    },[props])

  const handleOk = () => {
    setIsModalVisible(false);
  };

  const handleCancel = () => {
    setIsModalVisible(false);
  };

  return (
    <>
      <Modal title={props.store.operName==="stop"?'下架菜品':'上架菜品'}
        visible={isModalVisible} onOk={handleOk} onCancel={handleCancel}
         footer={
            [] // 设置footer为空，去掉 取消 确定默认按钮
            }
      >
        <p style={{textAlign: 'center'}}>请确认是否需要{props.store.operName==="stop"?'下架':'上架'}该菜品?</p>
        <Row>
            <Col span={12} push={2}>
                <Button
                onClick={() =>{
                  props.store.operName==="stop"?closeCui(props.store.data.cuiId,props.store.data.version):upCui(props.store.data.cuiId,props.store.data.version);
                  props.dispatch({type: 'changeRefresh',refresh: new Date().getTime()})
                  props.dispatch({type: 'changeStartStopModel',status: false})
                  
                }}
                >是</Button>
            </Col>
            <Col span={12}><Button 
            onClick={() =>{
              props.dispatch({type: 'changeStartStopModel',status: false})
            }}
            >否</Button></Col>
        </Row>
       
      </Modal>
    </>
  );
};

export default CancelModel;